package com.example.harmonyosproject.server.service.impl;

import com.example.harmonyosproject.pojo.Friend;
import com.example.harmonyosproject.pojo.Message;
import com.example.harmonyosproject.server.mapper.MessageMapper;
import com.example.harmonyosproject.server.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageMapper messageMapper;

    @Override
    public void send(Message message) {
        Message message1=new Message(
                message.getFriendId(),
                message.getUserId(),
                false,
                message.getText(),
                message.getImage()
        );
        messageMapper.addMessage(message);
        messageMapper.addMessage(message1);
    }

    @Override
    public List<Message> getAllMessage(Friend friend) {
        List<Message> messageList=messageMapper.getAllMessage(friend);
        return messageList;
    }
}
